// +----------------------------------------------------------------------
// | Project:   Xabad  
// +----------------------------------------------------------------------
// | CreateTime: 15/11/10  上午11:10
// +----------------------------------------------------------------------
// | Author:     xab(xab@xabad.cn)
// +----------------------------------------------------------------------
// | Description:
// +----------------------------------------------------------------------
package cn.xabad.commons.sample.ui.commons;

import cn.xabad.commons.converter.RetrofitError;
import cn.xabad.commons.sample.SampleApplication;
import cn.xabad.commons.sample.component.AppComponent;
import cn.xabad.commons.ui.CommFragment;
import com.github.johnpersano.supertoasts.SuperToast;

/**
 * DESC   :
 * AUTHOR : Xabad
 */
public abstract class BaseFragment extends CommFragment implements BaseViewInferface {

    protected SuperToast toast;


    @Override public void setting() {
        toast = new SuperToast(activity);
        setupComponent(SampleApplication.getComponent());
    }


    @Override public void showLoadingDialog(int resID) {
        showLoadingDialog(getString(resID));
    }


    @Override public void showLoadingDialog(String s) {

    }


    @Override public void hideLoadingDialog() {

    }


    protected boolean checkActivityState() {
        return activity != null && !activity.isFinishing();
    }


    @Override public void interError(RetrofitError error) {

    }


    public void onTip(int resID) {
        onTip(getString(resID));
    }


    @Override public void onTip(String message) {
        activity.runOnUiThread(() -> {
            toast.setText(message);
            toast.setDuration(1000);
            toast.show();
        });
    }


    protected abstract void setupComponent(AppComponent appComponent);
}
